/*******************************************************************************
* Copyright (c) 2010, 2018 西安秦晔信息科技有限公司
* Licensed under the Apache License, Version 2.0 (the "License");
*    you may not use this file except in compliance with the License.
*    You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*******************************************************************************/
package com.qinyeit.serviceapp.service.members.impl;

import com.qinyeit.serviceapp.entity.MemberCard;
import com.qinyeit.serviceapp.entity.enums.*;
import com.qinyeit.serviceapp.exception.BusinessRunTimeException;
import com.qinyetech.springstage.core.lang.QyMap;
import com.qinyetech.springstage.core.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.qinyetech.springstage.core.service.BaseService;
import com.qinyeit.serviceapp.entity.VipRecord;
import com.qinyeit.serviceapp.repository.members.VipRecordRepository;
import com.qinyeit.serviceapp.service.members.VipRecordService;

/** 
 * ClassName: VipRecordServiceImpl <br/> 
 * Function: 会员记录 业务实现 <br/> 
 * date: 2018-12-04 11:16:34 <br/> 
 * 
 * @author liuwenjin
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@Transactional
public class VipRecordServiceImpl extends BaseService<VipRecord, Long> implements VipRecordService {


	@Autowired
	private VipRecordRepository vipRecordRepository;


	@Override
	public VipRecord saveRecord(QyMap recordMap, Long merchantGroupId,String branchName) {
		VipRecord record = new VipRecord();
		record.setBranchName(branchName);
		record.setAfterGift(recordMap.getDouble("after_gift"));
		record.setAfterPoint(recordMap.getDouble("after_point"));
		record.setAfterValue(recordMap.getDouble("after_value"));
		record.setAmount(recordMap.getDouble("amount"));
		record.setBackDesc(recordMap.getString("back_desc"));
		record.setBeforeGift(recordMap.getDouble("before_gift"));
		record.setBeforeValue(recordMap.getDouble("before_value"));
		record.setBeforPoint(recordMap.getDouble("befor_point"));
		if (StringUtils.isNotBlank(recordMap.getString("card_mode"))){
			record.setCardMode(CardSpeciesType.valueOf(recordMap.getString("card_mode")));
		}
		record.setCardNo(recordMap.getString("card_no"));
		if (StringUtils.isNotBlank(recordMap.getString("card_state"))){
			record.setCardState(MemberCardState.valueOf(recordMap.getString("card_state")));
		}
		record.setCardType(recordMap.getString("card_type"));
		record.setCastBack(recordMap.getDouble("cast_back"));
		record.setDeposit(recordMap.getDouble("deposit"));
		record.setGiftPoint(recordMap.getDouble("gift_point"));
		record.setGiftValue(recordMap.getDouble("gift_value"));
		record.setOperatorName(recordMap.getString("operator_name"));
		record.setOrderNo(recordMap.getString("order_no"));
		if (StringUtils.isNotBlank(recordMap.getString("pay_type"))){
			record.setPayType(PayType.valueOf(recordMap.getString("pay_type")));
		}
		if (StringUtils.isNotBlank(recordMap.getString("platform"))){
			record.setPlatform(RechargeSource.valueOf(recordMap.getString("platform")));
		}
		record.setTargetNo(recordMap.getString("target_no"));
		if (StringUtils.isNotBlank(recordMap.getString("type"))){
			record.setType(VipRecordType.valueOf(recordMap.getString("type")));
		}else {
			record.setType(null);
		}
		record.setUndoTime(recordMap.getTime("undo_time"));
		record.setUuid(recordMap.getString("uuid"));
		record.setVipName(recordMap.getString("vip_name"));
		record.setVipPhone(recordMap.getString("vip_phone"));
		record.setMerchantGroupId(merchantGroupId);
		record = this.save(record);
		return record;
	}
}